/**
 * problem_027.cpp
 * Copyright (C) 2011 - xrose
 */

#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#define MAXAB 1000
using namespace std;

int isPrime(int numb);

int main (int argc, char const* argv[])
{
    int a, b;
    int cnt = 0;
    int mcnt = 0;
    int pab = 0;
    int mpab = 0;
    int n;              //n^2+a*n+b

    for(a = -MAXAB; (a<=MAXAB); a++)
    {
        for(b=-MAXAB; b<=MAXAB; b++)
        {
            for(n=0;;n++)
            {
                if(isPrime(n*n+a*n+b))
                {
                    if(cnt<=n)
                    {
                        cnt = n;
                        pab = a*b;
                    } else
                    {
                        continue;
                    }
                }else
                {
                    break;
                }
            }
        }
    }
    cout<<"cnt = "<<cnt<<" pab = "<<pab<<endl;
    return 0;
}

/*is a prime?*/
int isPrime(int numb)
{
    int sqrtnumb = int(sqrt(numb));
    int i;
    if(numb < 2)
    {
        return 0;
    } else if(numb == 2) return 1;
    else if((numb&1) == 0) return 0;
    for(i = 3; i<=sqrtnumb; i=i+2)
    {
        if(numb%i == 0) return 0;
    }
    return 1;
}
